        TITL DAI FIRMWARE 3EB26-3EC44  V1.0  Rev.1
        ORG   :EB26
*
*
*
************
* L - LOOK *
************
*
LOOKK   MVI   C,:03     Nr datablocks allowed
        CALL  :EB07     Scan keyb, display char,
 REM get addresses on stack
        LHLD  :005D     Get addr next instr
        XCHG            in DE
        MOV   A,C       Get nr of inputs done
        CPI   :03       No addr given?
        MVI   A,:00
        CZ    :EB56     No addr: Check CR given
        CNZ   :EB41     Else: store windows and
 REM start program
        STA   :0050     Set Look flag
        XCHG            Addr next instr in HL
        JMP   :EF35     Init RST 0
*
* SET LOOK WINDOWS. START LOOK:
*
* Entry: A=0, C=3 minus number of fields read.
* Exit:  Input 2 fields: A,C = 0.
*        Input 3 fields: A,C = FF. DE corrupted.
*        B preserved, HL corrupted.
*
L3E178  DCR   C
        DCR   C
        JZ    :EA62     Error if only 1 addr given
        POP   H         Get returnaddr from stack
        XTHL            haddr window in HL
        SHLD  :0048     Save haddr
        POP   H         Return addr from stack
        XTHL            laddr window in HL
        SHLD  :004A     Save laddr
        INR   C
        RZ              Ready if only window given
 REM
* If startaddress given:
 REM
        DCR   A         A=FF
        POP   H         Get returnaddr from stack
        POP   D         Get startaddr program in DE
        PCHL            Return
*
******************************
* GO/LOOK: CHECK FOR CAR.RET *
******************************
*
* Entry: B: Character to be checked.
* Exit:  AF corrupted, BCDEHL preserved.
*
L3E179  MOV   A,B       Get last char typed in
        SUI   :0D
        JNZ   :EA62     Error if not CR
        RET
*
*
*********************
* RESTART 0 (RST 0) *
*********************
*
* The RST 0 function is used to operate 'LOOK'.
* Via a timer 1 interrupt, RST 0 is called.
* The vectoraddress #EB5D must have been
* initialised by a Z2 or Z3 command.
*
* On entry, HL and PC are on stack (see 0000
* -0007).
*
L3E180  PUSH  PSW
        NOP
        LDA   :0047     Get stored EI/DI
        SUI   :FB
        JZ    :EB6C     Jump if EI stored
        MVI   A,:01     Else: Set int. mask
        STA   :FFF8     for timer 1 only
 REM
* Save all registers in RAM area:
 REM
L3E181  EI
        POP   PSW       Restore PSW
        POP   H         Restore HL
        SHLD  :0059     Save HL
        PUSH  PSW
        PUSH  B
        PUSH  D
        POP   H
        SHLD  :0057     Save DE
        POP   H
        SHLD  :0055     Save BC
        POP   H
        SHLD  :0053     Save PSW
        POP   H
        SHLD  :005D     Save PC
 REM
* Check if PC points to 004D-4E:
 REM
        LXI   D,:FFB3
        DAD   D
        XCHG            DE=PC+FFB3 (=PC-004D)
        LHLD  :0051     Get addr where to continue
        MOV   A,D
        ORA   A
        JNZ   :EB98     Jump if out of interrupt
 REM routine
        ORA   E
        CPI   :04
        JC    :EC3E     Jump if PC = 004D-4E
 REM
* Put returnaddress on stack if current instruction
* is a RST or a CALL instruction:
 REM
L3E182  MVI   B,:C7
        MOV   A,M       Get instr code of next instr
        CPI   :CD
        JZ    :EBAC     Jump if it is a CALL
        ANA   B         ) Check if it is a RST
        CMP   B         )
        JZ    :EBAE     Then jump
        MOV   A,M       Get instr code
        ANA   B         ) Check if it is a
        CPI   :C4       ) conditional CALL
        JNZ   :EBB0     Jump if not
L3E183  INX   H
        INX   H
L3E184  INX   H
        XTHL            Addr next instr on stack
 REM if it was a RST or CALL
 REM
* Check if current instruction is inside window:
 REM
L3E185  LXI   H,:0000
        DAD   SP
        SHLD  :005B     Save SP
        CALL  :EDE7     Exchange bytes in reg. save
 REM area
        LHLD  :0051     Get addr current instr
        XCHG            in DE
        LHLD  :004A     Get laddr window
        CALL  :EC45     Compare DE-HL
        JM    :EBDC     Jump if addr outside window
        LHLD  :0048     Get haddr window
        CALL  :EC45     Compare DE-HL
        JNC   :EBDC     Jump if addr outside window
 REM
* Print registers contents if address inside window:
 REM
        CALL  :ED3A     Print car.ret
        LXI   D,:0051   Startaddr reg. save area
        LXI   H,:EE9C   Startaddr symbol table
        CALL  :EE44     Print reg. contents
L3E186  CALL  :EEC2     Scan for Break pressed;
 REM evt run Break
        LHLD  :005D     Get addr next instr
 REM
* Disable UT to trace itself:
* Entry from init, RST0.
* HL is address where to continu.
 REM
L3E187  MVI   A,:EA
        CMP   H         Check if hibyte = EA
        JNZ   :EBEE     Jump if not
        MVI   A,:0D
        CMP   L         Check if lobyte = 0D
        JZ    :EA62     Then go to Error
 REM
* Check if next opcode is RST or EI/DI:
 REM
L3E188  DI
        SHLD  :0051     Save addr current instr
        LXI   D,:004C
        XCHG
        SHLD  :005D     Set addr next instr = 004C
        XCHG
        MOV   A,M       Get opcode of instr
        ANI   :C7
        CPI   :C7
        JZ    :EC33     Jump if RST
        LDA   :005F     Get int. mask
        CALL  :EF3E     Store it in TIC; set A=0
        STA   :FFF9     Reset timer 1 (trap
 REM immediate)
        MOV   A,M       Get opcode of instr
        ANI   :F7       ) Check if EI or DI
        SUI   :F3       )
        MOV   A,M       Get inst code
        XCHG            HL = #004C
        MVI   M,:FB     Load EI in #004C
        MVI   C,:03     3 instr bytes to be loaded
 REM into #004D-F
        JZ    :EC2C     Jump if instr is EI/DI
 REM
* Load next instruction into 004D-4F:
 REM
L3E189  LDAX  D         Get instr code
L3E190  INX   H
        MOV   M,A       Store it in #004D-F
        INX   D
        DCR   C
        JNZ   :EC19     Next byte of instr
*
* Run LOOK: Register contents:
*
*   If 'normal instr': 004C:    EI.
*                      004D-4F: Next instruction.
*
*   If RST *:          004C-4D: RST */ data **.
*                      004E:    RST 0.
*
*   If EI/DI:          004C:    EI.
*                      004D:    NOP.
*                      004E-50: Next instruction.
*                         This may cause problems,
*                         because 0050 is LOOK init
*                         flag.
*
        CALL  :EF30     XRA A; LXI H,#0050
        CMP   M         Check look flag
        MOV   M,A       Reset flag
        JZ    :EC63     If not Look init: restore
 REM CPU reg; cont on (005D/E)=
 REM 004C
        JMP   :ED9C     Else: Restore TIC/GICC/
 REM CPU reg/int.mask and 'GO'
 REM to (005D/E)=004C
 REM
* If instruction is EI or DI:
 REM
L3E191  STA   :0047     Store EI/DI instr
        XRA   A
        JMP   :EC1A     Load 00 in #004D, next instr
 REM in 004E-0050
 REM
* If a RST instruction:
 REM
L3E192  XCHG            HL=004C
        MVI   C,:02     Only 2-byte instruction
        MVI   A,:C7
        STA   :004E     Set (004E)=#C7 (=RST0)
        JMP   :EF44     RST*/data ** in 004C/D
 REM
* If PC points to 004D-004E:
 REM
L3E193  DAD   D         Set HL=0000-0001. This may
 REM cause re-entry problems due
 REM to stack manipulation
        SHLD  :005D     Save addr next instr (pnts
 REM to RST0)
        JMP   :EBB0
*
*
*
        END
